package exception;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.ExecutionException;

/**
 * 统一异常输出
 */
public class UnifiedExceptionConsole {

    /**
     * 异常打印
     * @param e 异常
     */
    public static void console(Exception e){
        if (e instanceof FileNotFoundException) {
            try {
                throw new MyException("找不到文件！");
            } catch (MyException ex) {
                ex.printStackTrace();
            }
        }
        else if (e instanceof UnsupportedEncodingException) {
            try {
                throw new MyException("不支持的字符编码！");
            } catch (MyException ex) {
                ex.printStackTrace();
            }
        }
        else if (e instanceof InterruptedException) {
            try {
                throw new MyException("线程中断异常！");
            } catch (MyException ex) {
                ex.printStackTrace();
            }
        }
        else if (e instanceof ExecutionException) {
            try {
                throw new MyException("线程执行异常！");
            } catch (MyException ex) {
                ex.printStackTrace();
            }
        }
        else {
            try {
                throw new MyException("其他未定义的异常！");
            } catch (MyException ex) {
                ex.printStackTrace();
            }
        }
        e.printStackTrace();
    }
}
